Passed
Pull Request — master (#347)
by Mirko
09:07
created

tools.js ➔ toggleChecks   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 9.4285
1
/***************************************************************************
2
 *  For license information see doc/license.txt
3
 *
4
 *  Unicode Reminder メモ
5
 *
6
 *  Javascript toolbox; browser-idependend functions
7
 ***************************************************************************/
8
9
10
// detect client size and scoll position
11
//
12
// based on http://www.ajaxschmiede.de/javascript/fenstergrose-und-scrollposition-in-javascript-auslesen/
13
14
function getClientWidth()
15
{
16
	if (typeof(window.innerWidth) == 'number')
17
		return window.innerWidth;  // Non-IE
18
	else
19
		return Math.max(document.documentElement.clientWidth, document.body.clientWidth);  // IE
20
}
21
22
function getClientHeight()
23
{
24
	if (typeof(window.innerHeight) == 'number')
25
		return window.innerHeight;  // Non-IE
26
	else
27
		return Math.max(document.documentElement.clientHeight, document.body.clientHeight);  // IE
28
}
29
30
function getScrollX()
31
{
32
	if (typeof(window.pageXOffset) == 'number')
33
		return window.pageXOffset;  // Non-IE
34
	else
35
		return Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);  // IE
36
}
37
38
function getScrollY()
39
{
40
	if (typeof(window.pageYOffset) == 'number')
41
		return window.pageYOffset;  // Non-IE
42
	else
43
		return Math.max(document.body.scrollTop, document.documentElement.scrollTop);  // IE
44
}
45
46
47
// detect document height
48
//
49
// from http://james.padolsey.com/javascript/get-document-height-cross-browser/
50
51
function getDocHeight()
52
{
53
	var D = document;
54
	return Math.max(
55
		D.body.scrollHeight, D.documentElement.scrollHeight,
56
		D.body.offsetHeight, D.documentElement.offsetHeight,
57
		D.body.clientHeight, D.documentElement.clientHeight
58
	);
59
}
60
61
62
// detect if the user scolled to the document bottom
63
64
function scrolledToBottom(tolerance)
65
{
66
	// alert(getScrollY() + " " + getClientHeight() + " " + getDocHeight());
67
	return getScrollY() + getClientHeight() + tolerance >= getDocHeight();
68
}
69
70
71
// create object for XMLHttp-Requests, i.e. for retreiving web pages or
72
// other XML pages via HTTP
73
74
function createXMLHttp()
75
{
76
	if (typeof XMLHttpRequest != 'undefined')
77
		return new XMLHttpRequest();
78
	else if (window.ActiveXObject)
79
	{
80
		var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp","MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.5.0"];
81
		for (var i = avers.length -1; i >= 0; i--)
82
		{
83
			try
84
			{
85
				httpObj = new ActiveXObject(avers[i]);
0 ignored issues
show
Bug introduced by
The variable httpObj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.httpObj.
Loading history...
86
				return httpObj;
87
			}
88
			catch(e)
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
89
			{
90
			}
91
		}
92
	}
93
	return null;
94
}
95
96
function toggleChecks(source, elementName) {
97
	checkboxes = document.getElementsByName(elementName);
0 ignored issues
show
Bug introduced by
The variable checkboxes seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.checkboxes.
Loading history...
98
	for (var i = 0, n = checkboxes.length; i < n; i++) {
99
		checkboxes[i].checked = source.checked;
100
	}
101
}
102